package com.younge.spring.api.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {
    private Integer code; // 响应码
    private String message;  //响应消息
    private T data; //响应数据

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(), data);
    }

    public static <T> CommonResult<String> field() {
        return new CommonResult<>(ResultCodeEnum.FIELD.getCode(), ResultCodeEnum.FIELD.getMessage(), null);
    }

    public static <T> CommonResult<String> error(String message) {
        return new CommonResult<>(ResultCodeEnum.FIELD.getCode(), message, null);
    }

    public static <T> CommonResult<String> forbidden() {
        return new CommonResult<>(ResultCodeEnum.FORBIDDEN.getCode(), ResultCodeEnum.FORBIDDEN.getMessage(), null);
    }

    public static <T> CommonResult<String> unauthorized() {
        return new CommonResult<>(ResultCodeEnum.UNAUTHORIZED.getCode(), ResultCodeEnum.UNAUTHORIZED.getMessage(),
                null);
    }

}
